package com.party.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.party.entity.Pmember;
import com.party.service.IPmemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class LoginController {

    @Autowired
    private IPmemberService memberService;

    @GetMapping("/")
    public String skipHome(){
        return "login";
    }

    @GetMapping("/register")
    public String register() {
        return "register";
    }

    @GetMapping("/add")
    public String add(){
        return "add";
    }


    @GetMapping("/index")
    public String index(Model model){
        List<Pmember> members = memberService.list();
        model.addAttribute("members", members);
        return "index";
    }

    @GetMapping("/search")
    public String search(Model model, @RequestParam String keyword) {
        List<Pmember> members = memberService.list(new QueryWrapper<Pmember>()
                .like("name", keyword));
        model.addAttribute("members", members);
        return "index";
    }
}
